#!/usr/bin/env python
# -*- coding=utf-8 -*-

import pygame
import sys

from pygame.sprite import Group

from settings import Settings
from ship import Ship
import game_functions as gf


def run_game():
    """
    初始化游戏，并创建一个屏幕对象
    """
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((
        ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    ship = Ship(ai_settings, screen)

    bullets = Group()
    # 开始游戏的主循环
    while True:
        # 监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        # 让最近汇总的屏幕可见
        gf.update_screen(ai_settings, screen, ship, bullets)


run_game()
